<?php



namespace App\Http\Instance;



use Illuminate\Support\Facades\Session;



class Singleton

{

    protected static $instance = null;

    private static  $config = [];





    public function __construct(){



    }



    /**

     * 单例模式入口

     * @return Singleton|null

     */

    public static function getInstance(){

        return self::$instance??new Singleton();

    }



    /**

     * 退出登录

     * @param $to 退出后跳转的地址

     * loginout

     */

    public function loginout(string $to){

        Session::flush();
        return redirect()->route($to);

    }



    /**

     * 通用返回值

     */

    public function returnMsg1($type,$errors){

        switch ($type){

            case 1:

                $arr = array('flag' => 'false', 'message' => 'error', 'error'  => $errors);

                break;

            case 2:

                $arr = array('flag' => 'success', 'message' => 'success', 'error'  => $errors);

                break;

        }



        return response()->json($arr);

    }



    /**

     * 获取支付宝相关参数

     */

    public  function getConfig():array {

        return $this->setAlipay1();

    }



    private  function  setAlipay1():array {

        return self::$config = [

            'app_id'         => config('global.app_id'),//你创建应用的APPID

            'notify_url'     => config('global.notify_url'),//异步回调地址

            'return_url'     => config('global.return_url'),//同步回调地址

            'ali_public_key' => config('global.ali_public_key'),//是支付宝公钥，不是应用公钥,  公钥要写成一行,不要换行

            'private_key'    => config('global.private_key'),//密钥,密钥要写成一行,不要换行

            'log'            => [

                'file'       => './logs/alipay.log',

                'level'      => 'info', // 建议生产环境等级调整为 info，开发环境为 debug

                'type'       => 'single', // optional, 可选 daily.

                'max_file'   => 30, // optional, 当 type 为 daily 时有效，默认 30 天

            ],

            'http'           => [ // optional

                'timeout'         => 5.0,

                'connect_timeout' => 5.0,

                // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)

            ],

            //'mode' => 'dev', // optional,设置此参数，将进入沙箱模式

        ];

    }



}
